package org.atlantis.grosbeak.lang.filefilter;

import java.io.File;
import java.io.FileFilter;

import org.atlantis.grosbeak.lang.Files;

/**
 * 符合正则表达式（仅针对文件名）的文件。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
public class RegexFilter implements FileFilter {

	private String pattern;

	public RegexFilter(String pattern) {
		this.pattern = pattern;
	}

	public boolean accept(File pathname) {
		String filename = Files.getName(pathname.getParent());
		if (filename.matches(pattern) || pathname.isDirectory())
			return true;
		return false;
	}
}
